using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.IO;

namespace WindowsApplication1
{
    public partial class TileEditorForm : Form
    {
        public Level level;
        AddSpawnPointForm addSpawnPointForm;
        string saveFile = "";
        public TileEditorForm()
        {
            InitializeComponent();
            level = new Level(this);
            Custom_DisplayArea.SetParent(this);
            Custom_TilePicker.SetParent(this);
            SGD.ManagedDirect3D.Instance.InitManagedDirect3D(Custom_DisplayArea, Custom_DisplayArea.Width, Custom_DisplayArea.Height, true, true);
            SGD.ManagedTextureManager.Instance.InitManagedTextureManager(SGD.ManagedDirect3D.Instance.Device, SGD.ManagedDirect3D.Instance.Sprite);
            Custom_DisplayArea.Invalidate();
            FillType_Brush.Checked = true;
        }
        ~TileEditorForm()
        {
            SGD.ManagedTextureManager.Instance.ShutdownManagedTextureManager();
        }

        public LoadedBitmap GetCurrentBitmap()
        {
            if(List_Tilesets.SelectedIndex < 0)
                return null;
            return List_Tilesets.Items[List_Tilesets.SelectedIndex] as LoadedBitmap;
        }

        public Layer GetCurrentLayer()
        {
            if (List_Layers.SelectedIndex < 0)
                return null;
            return List_Layers.Items[List_Layers.SelectedIndex] as Layer;
        }

        void Button_AddTileset_Click(object sender, EventArgs e)
        {
            level.AddBitmap();
        }

        void Button_RemoveTileset_Click(object sender, EventArgs e)
        {
            level.RemoveBitmap();
        }

        void Button_AddLayer_Click(object sender, EventArgs e)
        {
            level.AddLayer();
            Button_RemoveBoard.Enabled = (List_Layers.Items.Count > 2);
        }

        void Button_RemoveLayer_Click(object sender, EventArgs e)
        {
            level.RemoveLayer();
            Button_RemoveBoard.Enabled = (List_Layers.Items.Count > 2);
        }

        void Button_MoveUpBoard_Click(object sender, EventArgs e)
        {
            if (List_Layers.SelectedIndex > 0)
            {
                level.SwapLayers(List_Layers.SelectedIndex, List_Layers.SelectedIndex - 1);
                List_Layers.SelectedIndex--;
            }
        }

        void Button_MoveDownBoard_Click(object sender, EventArgs e)
        {
            if (List_Layers.SelectedIndex < List_Layers.Items.Count - 1)
            {
                level.SwapLayers(List_Layers.SelectedIndex, List_Layers.SelectedIndex + 1);
                List_Layers.SelectedIndex++;
            }
        }

        void ResetDisplayArea(){
            Custom_DisplayArea.AutoScrollMinSize = new Size((level.BoardWidth * level.TileWidth), level.BoardHeight * level.TileHeight);
            SGD.ManagedDirect3D.Instance.ChangeDisplayParam(Custom_DisplayArea, Custom_DisplayArea.AutoScrollMargin.Width, Custom_DisplayArea.AutoScrollMargin.Height, true, true);
            Custom_DisplayArea.Invalidate();
        }
        void BoardWidth_ValueChanged(object sender, EventArgs e)
        {
            level.BoardWidth = (int)BoardWidth.Value;
            ResetDisplayArea();
        }

        void BoardHeight_ValueChanged(object sender, EventArgs e)
        {
            level.BoardHeight = (int)BoardHeight.Value;
            ResetDisplayArea();
        }

        void TileWidth_ValueChanged(object sender, EventArgs e)
        {
            level.TileWidth = ((int)TileWidth.Value);
            Custom_TilePicker.Invalidate();
            ResetDisplayArea();
        }

        void TileHeight_ValueChanged(object sender, EventArgs e)
        {
            level.TileHeight = ((int)TileHeight.Value);
            Custom_TilePicker.Invalidate();
            ResetDisplayArea();
        }

        void List_Layers_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (List_Layers.SelectedIndex == -1)
                return;
            Button_RemoveBoard.Enabled = (List_Layers.Items.Count > 2);
            Button_MoveUpBoard.Enabled = (List_Layers.Items.Count >= 2);
            Button_MoveDownBoard.Enabled = (List_Layers.Items.Count >= 2);
            if((List_Layers.Items[List_Layers.SelectedIndex] as Layer).GetLayerType() == 1)
            {
                FillType_Stamp.Enabled = true;
            }
            else
            {
                FillType_Stamp.Enabled = false;
                FillType_Brush.Checked = true;
            }
            Custom_TilePicker.Invalidate();
            if(List_Layers.SelectedIndex > -1 && (List_Layers.Items[List_Layers.SelectedIndex] as Layer).GetLayerType() == 0)
                Custom_TilePicker.SetSelected(new Point(0, 0));
            Custom_DisplayArea.Invalidate();
        }

        void List_Tilesets_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(List_Tilesets.SelectedIndex > -1)
                Custom_TilePicker.AutoScrollMinSize = (List_Tilesets.Items[List_Tilesets.SelectedIndex] as LoadedBitmap).GetBitmap().Size;
            Custom_TilePicker.AutoScrollPosition = new Point(0, 0);
            Custom_TilePicker.SetSelected(new Point(0, 0));
            Custom_TilePicker.Invalidate();
        }

        void Checkbox_ShowBehind_CheckedChanged(object sender, EventArgs e)
        {
            Custom_DisplayArea.Invalidate();
        }

        void Checkbox_ShowGrid_CheckedChanged(object sender, EventArgs e)
        {
            Custom_DisplayArea.Invalidate();
        }

        public void SetTooltip()
        {
            if (level.doorToAdd.X >= 0)
            {
                Display_ToolTip.Text = "LMB: Pick a spot for the door to exit      RMB: Cancel";
            }
            if (level.spawnPointToAdd != null)
            {
                Display_ToolTip.Text = "LMB: Add a  '" + level.spawnPointToAdd.ToString() + "'      RMB: Cancel";
                return;
            }
            if (FillType_Brush.Checked)
            {
                Tool_ToolTip.Text = "LMB or RMB: Select a tile";
                Display_ToolTip.Text = "LMB: Sets the tile clicked      RMB: Empties the tile clicked";
            }
            if (FillType_PaintBucket.Checked)
            {
                Tool_ToolTip.Text = "LMB or RMB: Select a tile";
                Display_ToolTip.Text = "LMB: Fills in the area clicked      RMB: Empties the area clicked";
            }
            if (FillType_Stamp.Checked)
            {
                Tool_ToolTip.Text = "LMB: Select a starting tile      RMB: Toggle additional tiles";
                Display_ToolTip.Text = "LMB: Fills in the stamp area clicked      RMB: Empties the stamp area clicked";
            }
        }
        void FillType_Brush_CheckedChanged(object sender, EventArgs e)
        {
            SetTooltip();
        }

        void FillType_PaintBucket_CheckedChanged(object sender, EventArgs e)
        {
            SetTooltip();
        }

        void Stamp_CheckedChanged(object sender, EventArgs e)
        {
            SetTooltip();
        }

        void AddSpawnPoint(object sender, EventArgs e)
        {
            AddSpawnPointForm _form = (AddSpawnPointForm)sender;
            SpawnPoints _spawn = _form.List_SpawnTypes.Items[_form.List_SpawnTypes.SelectedIndex] as SpawnPoints;
            int _numberOfSpawns = (int)_form.NumberOfSpawns.Value;
            if (_form.Checkbox_Infinite.Checked)
                _numberOfSpawns = -1;
            level.spawnPointToAdd = new SpawnPoints(_spawn.Location, _spawn.Type, _numberOfSpawns, (int)_form.TimeBetweenSpawning.Value);
            SetTooltip();
        }

        public void RemoveSpawnPoint()
        {
            if (List_SpawnPoints.SelectedIndex < 0)
                return;
            int _oldIndex = List_SpawnPoints.SelectedIndex;
            List_SpawnPoints.Items.RemoveAt(List_SpawnPoints.SelectedIndex);
            if (List_SpawnPoints.Items.Count > 0)
            {
                if (_oldIndex > 0)
                {
                    if (_oldIndex < List_SpawnPoints.Items.Count)
                        List_SpawnPoints.SelectedIndex = _oldIndex;
                    else
                        List_SpawnPoints.SelectedIndex = List_SpawnPoints.Items.Count - 1;
                }
                else
                {
                    List_SpawnPoints.SelectedIndex = 0;
                }
            }
        }

        void Button_AddSpawnPoint_Click(object sender, EventArgs e)
        {

            if (addSpawnPointForm == null)
            {
                addSpawnPointForm = new AddSpawnPointForm(this);
                addSpawnPointForm.FormClosed += new FormClosedEventHandler(CloseSpawnPointWindow);
                addSpawnPointForm.AddSpawnPoint += new EventHandler(AddSpawnPoint);
            }
        }

        void Button_RemoveSpawnPoint_Click(object sender, EventArgs e)
        {
            RemoveSpawnPoint();
        }

        void CloseSpawnPointWindow(object sender, FormClosedEventArgs e)
        {
            addSpawnPointForm = null;
        }

        private void List_SpawnPoints_SelectedIndexChanged(object sender, EventArgs e)
        {
            Custom_DisplayArea.Redraw();
            bool _items = (List_SpawnPoints.Items.Count > 0 && List_SpawnPoints.SelectedIndex >= 0);
            Button_RemoveSpawnPoint.Enabled = _items;
            NumberOfSpawns.Enabled = _items;
            TimeBetweenSpawning.Enabled = _items;
            Checkbox_Infinite.Enabled = _items;
            if (_items)
            {
                SpawnPoints _spawn = List_SpawnPoints.Items[List_SpawnPoints.SelectedIndex] as SpawnPoints;
                if (_spawn.Type <= (int)SpawnPoints.Characters.SURVIVOR_RESPAWN)
                {
                    NumberOfSpawns.Enabled = false;
                    TimeBetweenSpawning.Enabled = false;
                    Checkbox_Infinite.Enabled = false;
                }
                else if (_spawn.NumberOfSpawns == -1)
                {
                    Checkbox_Infinite.Checked = true;
                    NumberOfSpawns.Enabled = false;
                }
                else
                {
                    Checkbox_Infinite.Checked = false;
                    NumberOfSpawns.Enabled = true;
                    NumberOfSpawns.Value = _spawn.NumberOfSpawns;
                }
                TimeBetweenSpawning.Value = _spawn.TimeBetweenSpanwing;
            }
        }

        private void Checkbox_ShowSpawnPoints_CheckedChanged(object sender, EventArgs e)
        {
            Custom_DisplayArea.Redraw();
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveLevel();
        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            saveFile = "";
            SaveLevel();
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoadLevel();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if(MessageBox.Show("Are you sure you want to quit?", "Quit?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                Close();
        }

        public void ClearLevel()
        {
            level.BoardWidth = 10;
            level.BoardHeight = 10;
            level.TileWidth = 32;
            level.TileHeight = 32;
            Checkbox_ShowBehind.Checked = true;
            Checkbox_ShowGrid.Checked = true;
            List_SpawnPoints.Items.Clear();
            List_Tilesets.Items.Clear();
            Custom_TilePicker.AutoScrollMinSize = new Size(0, 0);
            Custom_TilePicker.Invalidate();
            SGD.ManagedTextureManager.Instance.ShutdownManagedTextureManager();
            SGD.ManagedTextureManager.Instance.InitManagedTextureManager(SGD.ManagedDirect3D.Instance.Device, SGD.ManagedDirect3D.Instance.Sprite);
            List_Layers.Items.Clear();
            List_Layers.Items.Add(new Layer(1, 0, level.BoardWidth, level.BoardHeight));
            List_Layers.Items.Add(new Layer(1, 1, level.BoardWidth, level.BoardHeight));
            List_Layers.SelectedIndex = 1;
            level.layerNumber = 2;
            saveFile = "";
            NumberOfSpawns.Enabled = false;
            TimeBetweenSpawning.Enabled = false;
            Checkbox_Infinite.Enabled = false;
            Button_RemoveSpawnPoint.Enabled = false;
        }
        public void LoadLevel()
        {
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.Filter = "All Files|*.*|XML Files|*.xml";
            dlg.FilterIndex = 2;
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                ClearLevel();
                saveFile = dlg.FileName;
                this.Text = "Left4Dead Level Editor v1.0 - " + saveFile.Substring(saveFile.LastIndexOf('\\') + 1);
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ConformanceLevel = ConformanceLevel.Document;
                settings.IgnoreComments = true;
                settings.IgnoreWhitespace = true;
                using (XmlReader reader = XmlReader.Create(dlg.FileName, settings))
                {
                    reader.MoveToContent();
                    if (reader.Name == "Level")
                    {
                        reader.Read();
                        if (reader.Name == "Images" && reader.IsStartElement())
                        {
                            reader.Read();
                            while (reader.Name == "Image")
                            {
                                MessageBox.Show("Select the file " + reader.GetAttribute("Filename"));
                                OpenFileDialog imgDlg = new OpenFileDialog();
                                if (imgDlg.ShowDialog() == DialogResult.OK && imgDlg.CheckFileExists)
                                    List_Tilesets.Items.Add(new LoadedBitmap(imgDlg.FileName));
                                else
                                    MessageBox.Show("Failed to load level file.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                reader.Read();
                            }
                            List_Tilesets.SelectedIndex = List_Tilesets.Items.Count - 1;
                        }
                        reader.Read();
                        if (reader.Name == "Map" && reader.IsStartElement())
                        {
                            List_Layers.Items.Clear();
                            level.BoardWidth = Convert.ToInt32(reader["BoardWidth"]);
                            level.BoardHeight = Convert.ToInt32(reader["BoardHeight"]);
                            level.TileWidth = Convert.ToInt32(reader["TileWidth"]);
                            level.TileHeight = Convert.ToInt32(reader["TileHeight"]);
                            reader.Read();
                            int layerNumber = 1;
                            while (reader.Name == "Layer")
                            {
                                Layer layer = new Layer(layerNumber++, Convert.ToInt32(reader["Type"]), level.BoardWidth, level.BoardHeight);
                                int row = 0;
                                int col = 0;
                                reader.Read();
                                while (reader.Name == "Row")
                                {
                                    reader.Read();
                                    while (reader.Name == "Column")
                                    {
                                        LoadedBitmap bitmap = null;
                                        if (reader["Image"] != "null")
                                            for (int i = 0; i < List_Tilesets.Items.Count; i++)
                                                if ((List_Tilesets.Items[i] as LoadedBitmap).ToString() == reader["Image"])
                                                    bitmap = (List_Tilesets.Items[i] as LoadedBitmap);
                                        int x = Convert.ToInt32(reader["X"]);
                                        int y = Convert.ToInt32(reader["Y"]);
                                        int doorx = Convert.ToInt32(reader["DoorX"]);
                                        int doory = Convert.ToInt32(reader["DoorY"]);
                                        int collision = Convert.ToInt32(reader["Collision"]);
                                        layer.SetElement(row, col, bitmap, new Point(x, y), collision, new Point(doorx, doory));
                                        reader.Read();
                                        col++;
                                    }
                                    reader.Read();
                                    col = 0;
                                    row++;
                                }
                                reader.Read();
                                List_Layers.Items.Add(layer);
                            }
                            List_Layers.SelectedIndex = List_Layers.Items.Count - 1;
                        }
                        reader.Read();
                        if (reader.Name == "Spawns" && reader.IsStartElement())
                        {
                            reader.Read();
                            while (reader.Name == "Spawn")
                            {
                                
                                int type = Convert.ToInt32(reader["Type"]);
                                int x = Convert.ToInt32(reader["X"]);
                                int y = Convert.ToInt32(reader["Y"]);
                                int numberOfSpawns = Convert.ToInt32(reader["NumberOfSpawns"]);
                                int timeBetweenSpawns = Convert.ToInt32(reader["TimeBetweenSpawns"]);
                                List_SpawnPoints.Items.Add(new SpawnPoints(new Point(x, y), type, numberOfSpawns, timeBetweenSpawns));
                                reader.Read();
                            }
                        }
                    }
                }
            }
        }

        public void SaveLevel()
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "All Files|*.*|XML Files|*.xml";
            dlg.FilterIndex = 2;
            dlg.DefaultExt = ".xml";
            if (saveFile != "" || dlg.ShowDialog() == DialogResult.OK)
            {
                if(saveFile == "")
                    saveFile = dlg.FileName;
                this.Text = "Left4Dead Level Editor v1.0 - " + saveFile.Substring(saveFile.LastIndexOf('\\') + 1);
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.ConformanceLevel = ConformanceLevel.Document;
                settings.Indent = true;
                using (XmlWriter writer = XmlWriter.Create(saveFile, settings))
                {
                    writer.WriteStartElement("Level");
                    writer.WriteAttributeString("Version", "1.0");
                    {
                        writer.WriteStartElement("Images");
                        for (int imageIndex = 0; imageIndex < List_Tilesets.Items.Count; imageIndex++)
                        {
                            LoadedBitmap image = List_Tilesets.Items[imageIndex] as LoadedBitmap;
                            writer.WriteStartElement("Image");
                            writer.WriteAttributeString("Filename", image.ToString());
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                        writer.WriteStartElement("Map");
                        writer.WriteAttributeString("BoardWidth", level.BoardWidth.ToString());
                        writer.WriteAttributeString("BoardHeight", level.BoardHeight.ToString());
                        writer.WriteAttributeString("TileWidth", level.TileWidth.ToString());
                        writer.WriteAttributeString("TileHeight", level.TileHeight.ToString());
                        for (int layerIndex = 0; layerIndex < List_Layers.Items.Count; layerIndex++)
                        {
                            Layer layer = List_Layers.Items[layerIndex] as Layer;
                            writer.WriteStartElement("Layer");
                            writer.WriteAttributeString("Type", layer.GetLayerType().ToString());
                            for (int x = 0; x < level.BoardWidth; x++)
                            {
                                writer.WriteStartElement("Row");
                                for (int y = 0; y < level.BoardHeight; y++)
                                {
                                    Tile tile = layer.GetElement(x, y) as Tile;
                                    writer.WriteStartElement("Column");
                                    if (tile.CurrentBitmap == null)
                                        writer.WriteAttributeString("Image", "null");
                                    else
                                        writer.WriteAttributeString("Image", tile.CurrentBitmap.ToString());
                                    writer.WriteAttributeString("X", tile.TileLocation.X.ToString());
                                    writer.WriteAttributeString("Y", tile.TileLocation.Y.ToString());
                                    writer.WriteAttributeString("Collision", tile.Collision.ToString());
                                    writer.WriteAttributeString("DoorX", tile.DoorTo.X.ToString());
                                    writer.WriteAttributeString("DoorY", tile.DoorTo.Y.ToString());
                                    writer.WriteEndElement();
                                }
                                writer.WriteEndElement();
                            }
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                        writer.WriteStartElement("Spawns");
                        for (int spawnIndex = 0; spawnIndex < List_SpawnPoints.Items.Count; spawnIndex++)
                        {
                            SpawnPoints spawn = List_SpawnPoints.Items[spawnIndex] as SpawnPoints;
                            writer.WriteStartElement("Spawn");
                            writer.WriteAttributeString("Type", spawn.Type.ToString());
                            writer.WriteAttributeString("X", spawn.Location.X.ToString());
                            writer.WriteAttributeString("Y", spawn.Location.Y.ToString());
                            writer.WriteAttributeString("NumberOfSpawns", spawn.NumberOfSpawns.ToString());
                            writer.WriteAttributeString("TimeBetweenSpawns", spawn.TimeBetweenSpanwing.ToString());
                            writer.WriteEndElement();
                        }
                        writer.WriteEndElement();
                    }
                    writer.WriteEndElement();
                }
            }
        }

        private void ExportLevel()
        {
            SaveFileDialog dlg = new SaveFileDialog();
            dlg.Filter = "All Files|*.*|Left4Dead Level Files|*.l4d";
            dlg.FilterIndex = 2;
            dlg.DefaultExt = ".l4d";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                //StreamWriter writer = new StreamWriter(dlg.FileName);

                FileStream stream = File.Create(dlg.FileName);
                BinaryWriter writer = new BinaryWriter(stream);

                using (writer)
                {
                    for (int imageIndex = 0; imageIndex < List_Tilesets.Items.Count; imageIndex++)
                    {
                        LoadedBitmap image = List_Tilesets.Items[imageIndex] as LoadedBitmap;
                        writer.Write(('{' + image.ToString() + '}').ToCharArray());
                    }
                    writer.Write(level.BoardWidth);
                    writer.Write(level.BoardHeight);
                    writer.Write(level.TileWidth);
                    writer.Write(level.TileHeight);
                    writer.Write(List_Layers.Items.Count);
                    for (int layerIndex = 0; layerIndex < List_Layers.Items.Count; layerIndex++)
                    {
                        Layer layer = List_Layers.Items[layerIndex] as Layer;
                        writer.Write(layer.GetLayerType());
                        for (int x = 0; x < level.BoardWidth; x++)
                        {
                            for (int y = 0; y < level.BoardHeight; y++)
                            {
                                Tile tile = layer.GetElement(x, y) as Tile;
                                writer.Write(tile.Collision);
                                if (tile.Collision == (int)Tile.CollisionTypes.NO_COLLISION)
                                {
                                    int imageID = -1;
                                    for (int i = 0; i < List_Tilesets.Items.Count; i++)
                                    {
                                        if (tile.CurrentBitmap != null && tile.CurrentBitmap.ToString() == List_Tilesets.Items[i].ToString())
                                        {
                                            imageID = i;
                                            break;
                                        }
                                    }
                                    writer.Write(imageID);
                                    if (imageID != -1)
                                    {
                                        writer.Write(tile.TileLocation.X);
                                        writer.Write(tile.TileLocation.Y);
                                    }
                                }
                                else if (tile.Collision == (int)Tile.CollisionTypes.DOOR)
                                {
                                    writer.Write(tile.DoorTo.X);
                                    writer.Write(tile.DoorTo.Y);
                                }
                            }
                        }
                    }
                    writer.Write(List_SpawnPoints.Items.Count);
                    for (int spawnIndex = 0; spawnIndex < List_SpawnPoints.Items.Count; spawnIndex++)
                    {
                        SpawnPoints spawn = List_SpawnPoints.Items[spawnIndex] as SpawnPoints;
                        writer.Write(spawn.Type);
                        writer.Write(spawn.Location.X);
                        writer.Write(spawn.Location.Y);
                        writer.Write(spawn.NumberOfSpawns);
                        writer.Write(spawn.TimeBetweenSpanwing);
                    }
                }
            }
        }

        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to start a new project?", "New Project?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                ClearLevel();
            }
        }

        private void NumberOfSpawns_ValueChanged(object sender, EventArgs e)
        {
            (List_SpawnPoints.Items[List_SpawnPoints.SelectedIndex] as SpawnPoints).NumberOfSpawns = (int)NumberOfSpawns.Value;
        }

        private void Checkbox_Infinite_CheckedChanged(object sender, EventArgs e)
        {
            NumberOfSpawns.Enabled = !(Checkbox_Infinite.Checked);
            if (Checkbox_Infinite.Checked)
                (List_SpawnPoints.Items[List_SpawnPoints.SelectedIndex] as SpawnPoints).NumberOfSpawns = -1;
            else
                (List_SpawnPoints.Items[List_SpawnPoints.SelectedIndex] as SpawnPoints).NumberOfSpawns = (int)NumberOfSpawns.Value;
        }

        private void TimeBetweenSpawning_ValueChanged(object sender, EventArgs e)
        {
            (List_SpawnPoints.Items[List_SpawnPoints.SelectedIndex] as SpawnPoints).TimeBetweenSpanwing = (int)TimeBetweenSpawning.Value;
        }

        private void exportLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ExportLevel();
        }
    }
}